/**
 * 速放贷APP
 *
 * @author wangle
 */
angular.module('partnerApp', ['ngResource', 'ngRoute', 'ngAnimate', 'ngSanitize'])
.constant('DEBUG', false)
.filter('empty', function () {
    return function (originValue, defaultValue) {
        return originValue === 0 ? 0 : (originValue ? originValue : defaultValue);
    }
}).directive('stringToNumber', function () {
    return {
        require: 'ngModel', link: function (scope, element, attrs, ngModel) {
            ngModel.$parsers.push(function (value) {
                return '' + value;
            });
            ngModel.$formatters.push(function (value) {
                return parseInt(value);
            });
        }
    };
}).config(['$routeProvider', function ($routeProvider) {
    $routeProvider.when('/:page/:param?', {
        templateUrl: function ($routeParams) {
            var page = $routeParams.page;
            if (/^account/.test(page)) {
                //进来先查询用户信息
                ajaxRequest({
                    data: getRequestData("customerInfo"), async: false
                }, function (data) {
                    setLoginCustomer(data.data);
                }, function () {
                }, true);
                if (!getLoginInfo('token')) { //需要登录 //但是没有登录,跳转登录
                    return 'login.html';
                }
            }
            return $routeParams.page + '.html';
        }
    }).otherwise({
        templateUrl: function () {
            return 'partnerRegister.html';
        }
    });
}]).run(['$rootScope', function ($rootScope) {
    window.rootScope = $rootScope;
    $rootScope.$on('$routeChangeStart', function (evt, routeProvider) {
        $rootScope._PAGE = routeProvider.params.page;
        $rootScope._NAV_HIDE = false;
        $rootScope._FIRST_STARTED = !getStorage('started');
        $rootScope._LOGINED = !!getLoginInfo('token');
        delete $rootScope._PAGE_ANIMATE;
    });
    $rootScope.$on('$routeChangeSuccess', function (evt, routeProvider) {
        setFontSize(640, 320, 16);
    });
}]);